<?php
session_start();
include_once "../apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$predicateName = $_POST["predicate_name"];
$predicateDetail = $_POST["predicate_detail"];
$price = $_POST["price"];

$predicateId = $_GET["predicate_id"];
if($predicateId == "" || $predicateId == null){
	$predicateId = $_POST["predicate_id"];
}

$mode = $_GET["mode"];
if($mode == "" || $mode == null){
	$mode = $_POST["mode"];
}

$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}

if($mode == "insert"){
	$arrData["predicate_name"] = "".$predicateName."";
	$arrData["predicate_detail"] ="".$predicateDetail."";
	$arrData["price"] ="".$price."";
	$arrData["create_date"] = "".date("Y-m-d")."";
	$arrData["create_by"] = "".$_SESSION["user_name"]."";
	$managerIUDS->inserData($arrData, "predicate");
	header("Location:../contents/predicate_main.php");
}else if($mode == "delete"){
	$arrPrimaryKey["predicate_id"] = "".$predicateId."";
	$managerIUDS->deleteData("predicate", $arrPrimaryKey, "");
	header("Location:../contents/predicate_main.php");
}else if($mode == "update"){
	$arrData["predicate_name"] = "".$predicateName."";
	$arrData["predicate_detail"] ="".$predicateDetail."";
	$arrData["price"] ="".$price."";
	$arrData["update_date"] = "".date("Y-m-d")."";
	$arrData["update_by"] = "".$_SESSION["user_name"]."";
	$arrPrimaryKey["predicate_id"] = "".$predicateId."";
	$managerIUDS->updateData($arrData, "predicate", $arrPrimaryKey, "");
	header("Location:../contents/predicate_main.php");
}else if($mode == "search"){
	$predicateName = $_GET["predicate_name"];
	header("Location:../contents/predicate_main.php?mode=search&page=".$page."&predicate_name=".urlencode($predicateName));
}else if($mode == "listPredicateData"){
	$predicateData = array();
	$predicateName = $_GET["predicate_name"];
	if($predicateName == "" || $predicateName == null){
		$predicateName = $_POST["predicate_name"];
	}
	$predicateData = $managerIUDS->queryData("predicate_name", "predicate", " WHERE predicate_name LIKE '%".$predicateName."%'", "2", "");
	if(sizeof($predicateData)<=0){
		$predicateData = "";
	}
	echo json_encode($predicateData);
}
?>